<template>
	<!-- 页面容器 -->
	<view class="page-wraper">
		<!-- 页面头部 -->
		<view class="page-header">
			<view class="title flex">
				<view class="top-head">
					<span class="title-left">工单信息</span>
				</view>
				<view class="top-foot">
					<input class="input-style uni-input" v-model="mo" focus placeholder="输入工单或扫码" />
				</view>
				<view class="top-foot">
					<button :class="{'bins': iphone=='huawei', 'bin': iphone != 'huawei'}" type="primary" size="mini" @click="OnSearch">搜索</button>
				</view>
				<view class="top-foot">
					<yt-scanCode :class="{'bins': iphone=='huawei', 'bin': iphone != 'huawei'}" btnName="扫码" @getScanCode="OnScanningCode"></yt-scanCode>
				</view>
			</view>
			<uni-card>
				<view style="height:41vh">
					<zb-table @rowClick="rowClick" :columns="column" :stripe="true" :border="true" :highlight="true"
						:data="data"></zb-table>
				</view>
			</uni-card>
		</view>
		<!-- 页面主体 -->
		<view class="page-main">
			<view class="title flex">
				<view class="top-head1">
					<span class="title-left">文档管理</span>
				</view>
				<view class="top-foot" style="width: 150px;">
				</view>
				<view class="top-foot">
					<button :class="{'bins1': iphone=='huawei', 'bin1': iphone != 'huawei'}" type="primary" size="mini" @click="uploudfile">上传</button>
				</view>
				<view class="top-foot">
					<button :class="{'bins1': iphone=='huawei', 'bin1': iphone != 'huawei'}" type="warn" size="mini" @click="Delete">删除</button>
				</view>
			</view>
			<uni-card>
				<view style="height:41vh">
					<zb-table @toggleRowSelection="toggleRowSelection" @toggleAllSelection="toggleAllSelection"
						:columns="column1" :stripe="true" :border="true" :data="data1"></zb-table>
				</view>
			</uni-card>
		</view>
	</view>
</template>
<script>
	import {
		getplanJobGxList,
		getJobFileByJobId,
		delFileRecordById
	} from '@/api/system/document.js'
	import config from '@/config'
	export default {
		data() {
			return {
				mo: "",
				column: [{
						name: 'pstut_statename',
						label: '工单状态',
					},
					{
						name: 'jobCode',
						label: 'MO号',
						width: 150,
					},
					{
						name: 'mate_code',
						label: '物料编号',
					},
					{
						name: 'mate_designnumber',
						label: '图号',
					},
					{
						name: 'versionnum',
						label: '图号版本',
					},
					{
						name: 'job_code',
						label: '工序号'
					},
					{
						name: 'job_name',
						label: '工序名称'
					},
					{
						name: 'stut_statename',
						label: '工序状态'
					},
					{
						name: 'job_plannum',
						label: '计划数',
						width: 80,
					},
					{
						name: 'job_prudctnum',
						label: '投产数',
						width: 80,
					},
					{
						name: 'job_actualamount',
						label: '完成数',
						width: 80,
					}
				],
				column1: [{
						type: 'selection',
						width: 50,
					}, {
						name: 'fileName',
						label: '文件名称',
						width: 200,
					},
					{
						name: 'fileType',
						label: '文件类型',
						width: 200,
					},
					{
						name: 'createTime1',
						label: '上传时间',
						width: 200,
					}, {
						name: 'patyName',
						label: '上传人',
						width: 200,
					}, {
						name: 'fileUrl',
						label: '图片',
						type: "img",
						align: "center",
						width: 200,
					},
				],
				iphone:"",
				data: [],
				data1: [],
				fileIds: "",
				jobId: "",
				parme: "",
			}
		},
		created() {
            this.getPhoneModel()
		},
		onShow() {
			if (this.jobId != "") {
				this.onRow();
			}
		},
		methods: {
			getPhoneModel() {
				let brand = '';
				let zhDev = {
					'apple': 'iPhone',
					'samsung': '三星',
					'huawei': '华为',
					'xiaomi': '小米',
					'oppo': 'OPPO',
					'vivo': 'Vivo',
					'oneplus': '一加',
					'sony': '索尼',
					'lg': 'LG',
					'motorola': '摩托罗拉',
					'google': '谷歌',
					'nokia': '诺基亚',
					'htc': 'HTC',
					'lenovo': '联想',
					'asus': '华硕',
					'zte': '中兴',
					'meizu': '魅族',
					'coolpad': '酷派',
				}
				if (uni.getSystemInfoSync().platform === 'android' || 'ios') {
					let model = uni.getSystemInfoSync().brand.toLowerCase();
						console.log('手机品牌1', model)
					this.iphone=model;
					brand = zhDev[model] ? zhDev[model] : '其它'
				} else {
					brand = '其它'
				}
				console.log('手机品牌2', brand)
			},
			OnScanningCode(res) {
				this.mo = res;
				this.OnSearch();
			},
			OnSearch() {
				this.data = [];
				this.data1 = [];
				if (this.mo == "") {
					this.$modal.msgError(`工单为空!`)
				} else {
					getplanJobGxList(this.mo, "", "", 1, 99999).then(res => {
						this.data = res.list
					})
				}
			},
			toggleAllSelection(checked, arr) {
				let fileId = [];
				for (var i = 0; i < arr.length; i++) {
					fileId.push(arr[i].fileId)
				}
				this.fileIds = "";
				this.fileIds = fileId.join(",");
			},
			toggleRowSelection(checked, arr) {
				let fileId = [];
				for (var i = 0; i < arr.length; i++) {
					fileId.push(arr[i].fileId)
				}
				this.fileIds = "";
				this.fileIds = fileId.join(",");
			},
			uploudfile() {
				console.log(this.parme)
				if(this.parme !== ""){
					uni.navigateTo({
						url: '/pages/document/add?parme=' + JSON.stringify(this.parme)
					})
				}else{
					this.$modal.msgError(`请选择一行数据`)
				}
				
			},
			Delete() {
				//console.log(this.fileIds)
				if (this.fileIds === "" || this.fileIds === null) {
					this.$modal.msgError(`选择一条数据！`)
				} else {
					delFileRecordById(this.fileIds).then(res => {
						if (res.code === 200) {
							this.$modal.msgSuccess("删除成功")
							this.onRow();
						} else {
							this.$modal.msgError(`删除失败!`)
						}

					})
				}
			},
			rowClick(row, index) {
				this.jobId = row.jobId;
				this.parme = row;
				this.onRow();
			},
			onRow() {
				getJobFileByJobId(this.jobId).then(res => {
					let data = [];
					for (var i = 0; i < res.data.length; i++) {
						var a = {
							"fileName": res.data[i].fileName,
							"fileType": res.data[i].fileType,
							"createTime1": res.data[i].createTime1,
							"patyName": res.data[i].patyName,
							"fileUrl": config.baseUrl_minio + res.data[i].fileUrl,
							"fileId": res.data[i].fileId,
						}
						data.push(a);
					}
					this.data1 = data
				})
			}
		}
	}
</script>

<style lang="scss">
	/* 设置页面背景色 */
	.page-wraper {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 100%;
	}

	.page-header {
		margin-top: 0.5vh;
		height: 49.5vh;
		background: #fff;
	}

	.page-main {
		height: 49.5vh;
		background: #fff;
	}

	.title {
		background-color: rgba(245, 247, 250, 1);
		height: 6vh;
		line-height: 6vh;
		text-align: left;
		font-size: 36rpx;
		color: #111;
		border-bottom: 1px solid #dcdfe6;
	}

	.title-left {
		margin-left: 20rpx;
	}

	.input-style {
		background-color: #ffffff;
		height: 5vh;
		margin-top: 2%;
		width: 150px;
	}

	.bin {
		margin-top: 0.5vh;
	}
	.bins {
		margin-top: 1vh;
	}

	.top-head {
		width: 60%;
	}

	.top-head1 {
		width: 60%;
	}

	.top-foot {
		margin-left: 1.5%;
	}

	.bin1 {
		margin-top: 0.5vh;
	}

	.bins1 {
		margin-top: 1vh;
	}

	::v-deep {
		.uni-card {
			margin: 8px !important;
			padding: 0 !important;

			.uni-card__content {
				padding: 0 !important;
			}
		}
	}
</style>